<?php
class system_view
{
    public function view_display_module($linkFile)
	{
        $linkFile = PATH_TEMPLATE.'/module/'.$linkFile.'/'.$linkFile.'.phtml';
		$contentHtml = file_exists($linkFile)?file_get_contents($linkFile):"Not find template";
        if(ZIPHTML==true)
        $contentHtml = str_replace(array("\n","\r","\t",'  '),'',$contentHtml);
		return $contentHtml;
	}
    
	public function view_display($linkFile)
	{
        $linkFile = PATH_TEMPLATE.'/'.COMCUR.'/'.$linkFile.'.phtml';
		$contentHtml = file_exists($linkFile)?file_get_contents($linkFile):"Not find template";
        if(ZIPHTML==true)
        $contentHtml = str_replace(array("\n","\r","\t",'  '),'',$contentHtml);
		return $contentHtml;
	}
	
	public function view_display_layout($linkFile)
	{
		$linkFile = PATH_TEMPLATE.'/layout/'.$linkFile.'.phtml';
		$contentHtml = file_exists($linkFile)?file_get_contents($linkFile):"Not find template";
        if(ZIPHTML==true)
        $contentHtml = str_replace(array("\n","\r","\t",'  '),'',$contentHtml);
		return $contentHtml;
	}
    
    public function view_split($strHtml)
	{
		$arrHtml = explode('[SPLIT]',$strHtml);		
		return $arrHtml;
	}
	
	public function view_get_block_html($strHtml)
	{	 
		$strHtml = preg_replace("/\[LOOP (.+?)\](.+?)\[\/LOOP (.+?)\]/is", "=====\\1_____\\2=====" ,$strHtml);
		$arr = explode('=====',$strHtml);
		foreach($arr as $val){
			$arrG = explode('_____',$val);
			if( !empty($arrG[0]) && !empty($arrG[1]) )
			$arrHtml[$arrG[0]] = $arrG[1];
		} return $arrHtml;
	}
    
    public function view_get_block($strHtml)
	{	 
        preg_match_all('/{(.+?)}/is', $strHtml, $result);
        return $result;
	}
    
    
	public function view_assign_act($strHtml, $arrVal, $type=NULL)
	{	        
		if($type=='display'){
			$arr = $this->view_get_block($strHtml);
        }
        foreach ( $arrVal as $block => $val ){
			$strHtml = preg_replace('/\{'.$block.'\}/is', $val ,$strHtml);
            
            if($type=='display'){
			if( in_array($block.':none',$arr[1]) )
            {
                if( empty($val) )
                {
                   
                    $strHtml = preg_replace('/\{'.$block.':none\}/is', 'display:none;' ,$strHtml);
                
                } else {
                   
                    $strHtml = preg_replace('/\{'.$block.':none\}/is', 'display:block;' ,$strHtml);
                }
            }}
        
        } 
             
        
        return $strHtml;
	}
    
    public function view_assign($strHtml, $arrVal)
	{	
        foreach ( $arrVal as $block => $val ){
			$strHtml = preg_replace('/\{'.$block.'\}/is', $val ,$strHtml);        
        } 

        return $strHtml;
	}

	public function view_assign_block($strHtml,$arrVal)
	{
		foreach ( $arrVal as $block => $val ){
			$strHtml = preg_replace("/\[OPEN ".$block."\](.+?)\[CLOSE ".$block."\]/is", $val,$strHtml);
		} return $strHtml;
	}
    
    public function view_assign_block_loop($strHtml, $arrVal)
	{
        $result_Html = '';
        foreach ($arrVal as $row)
        {
            $strHtml2 = $strHtml;
            foreach ( $row as $block => $val ){
                $strHtml2 = preg_replace('/\{'.$block.'\}/is', $val ,$strHtml2);
                
            }
            $result_Html .= $strHtml2;
        }
        return $result_Html;
	}
}
?>